#ifndef __BUOLA_GUI_X11_CX11CLIPBOARD_H__
#define __BUOLA_GUI_X11_CX11CLIPBOARD_H__

#include <buola/gui/x11/auto.h>

#include <buola/gui/cclipboard.h>
#include <X11/Xlib.h>

namespace buola { namespace gui { namespace x11 {

class CX11Clipboard : public CClipboard
{
protected:
    CX11Clipboard(int pType);

//server interface
    bool IsOwned()              {   return mOwned;  }
    bool OwnSelection();
    bool ReleaseSelection();

//client interface
    void InitTargets();
    void AddTarget(Atom);
    void AddTarget(const std::wstring&);
    void AskForSelection(int);

//server internal
    void ServeTargetsList();
    void ServeText(const std::wstring&);
    void ServeData(void*,std::size_t);

//client internal
    bool IsTargetAvailable(Atom);
    bool IsTargetAvailable(const std::wstring&);

    void AskForData(Atom);

//callbacks
    void ProcessSelectionRequest(XSelectionRequestEvent*);
    void ProcessSelectionClear(XSelectionClearEvent*);
    void ProcessSelectionNotify(XSelectionEvent*);

//internal
    CPhysicalWindow *GetProxy();


//static functions
    static int AtomToType(Atom);
    static Atom TypeToAtom(int);

//intrinsic data
    Atom mAtom;
    CPhysicalWindow *mProxy;

//common data
    Window mPartner;
    Atom mProperty;
    std::vector<Atom> mAvailableTargets;    //served (and locally available)
                                        //or remotely available
    Atom mTarget;
    std::wstring mMIMETarget;

//server data
    bool mOwned;

//client data
    Atom mActualType;
    int mRequestedTarget;
    int mClientMoment;

//friends
    friend class CClipboard;
    friend class CX11Toolkit;
    friend class CX11Drag;
    friend class CX11Dispatcher;
};

/*namespace x11*/ } /*namespace gui*/ } /*namespace buola*/ }

#endif
